#!/bin/bash
if(test -L $0) then auxlink=`ls -l $0 | sed 's/^[^>]*-> //g'`; M_HOME=`dirname $auxlink`/; else M_HOME=`dirname $0`/; fi; cd $M_HOME
./udev* || exit 1
. ../before || exit 1
ARG='ARCH=arm CROSS_COMPILE=arm-none-linux-gnueabi-'
sb2 make $ARG defconfig > /dev/null
sed -i 's/# CONFIG_FEATURE_EDITING_FANCY_PROMPT is not set/CONFIG_FEATURE_EDITING_FANCY_PROMPT=y/' .config
sed -i 's/^CONFIG_MDEV=y/\# CONFIG_MDEV is not set/g' .config
sed -i 's/^CONFIG_FEATURE_MDEV_CONF=y/\# CONFIG_FEATURE_MDEV_CONF is not set/g' .config
sed -i 's/^CONFIG_FEATURE_MDEV_RENAME=y/\# CONFIG_FEATURE_MDEV_RENAME is not set/g' .config
sed -i 's/^CONFIG_FEATURE_MDEV_RENAME_REGEXP=y/\# CONFIG_FEATURE_MDEV_RENAME_REGEXP is not set/g' .config
sed -i 's/^CONFIG_FEATURE_MDEV_EXEC=y/\# CONFIG_FEATURE_MDEV_EXEC is not set/g' .config
sed -i 's/^CONFIG_FEATURE_MDEV_LOAD_FIRMWARE=y/\# CONFIG_FEATURE_MDEV_LOAD_FIRMWARE is not set/g' .config
sb2 make > /dev/null
sb2 make install > /dev/null
cp -a ./_install/* $ROOTFS

pushd $ROOTFS

cat >etc/inittab<<eof
::sysinit:/etc/init.d/rcS
::respawn:/sbin/getty 115200 ttyS0 vt100 -n -l /bin/sh 
::restart:/sbin/init
::ctrlaltdel:/sbin/reboot
::shutdown:/bin/umount -a -r
::shutdown:/sbin/swapoff -a
eof

cat >etc/fstab <<eof
proc /proc proc defaults
# /dev/mmcblk0p1 /media/sdcard auto defaults,sync,noauto
eof

cat >etc/init.d/rcS <<eof
#!/bin/sh
mount -t sysfs sysfs  /sys
mount -t tmpfs tmpfs  /dev
mount -t proc  proc   /proc
mount -t tmpfs tmpfs  /tmp
route add default gw 192.168.0.1
mknod /dev/null c 1 3
udevd --daemon
udevadm trigger
eof

chmod +x etc/init.d/rcS

touch etc/mdev.conf

cat >etc/resolv.conf <<eof
nameserver 202.120.2.101
nameserver 202.112.26.34
eof

cat >etc/hosts <<eof
127.0.0.1 localhost:localdomain localhost
eof

#cat >etc/ld.so.conf <<eof
#/lib
#/usr/lib
#eof

cat >etc/passwd <<eof
root::0:0:root:/root:/bin/sh
nobody::60000:60000:nobody:/notexist:/bin/false
eof

cat >etc/group <<eof
root::0:
nobody::60000:
eof

popd

touch $ROOTFS/.`basename $0`
